package com.zfei.gfb.query.h5;

import com.zfei.gfb.bean.Const;
import com.zfei.gfb.bean.Page;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author fgh
 */
@ApiModel
public class H5HouseQuery extends Page {

    @ApiModelProperty("最低租金")
    private Integer minPrice;
    @ApiModelProperty("最高租金")
    private Integer maxPrice;

    @ApiModelProperty("是否认证，0:认证中 1:已认证 2:未通过")
    private Integer status;

    @ApiModelProperty("户型")
    private String unitType;

    public Integer getMinPrice() {
        return minPrice;
    }

    public void setMinPrice(Integer minPrice) {
        this.minPrice = minPrice;
    }

    public Integer getMaxPrice() {
        return maxPrice;
    }

    public void setMaxPrice(Integer maxPrice) {
        this.maxPrice = maxPrice;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getUnitType() {
        return unitType;
    }

    public void setUnitType(String unitType) {
        this.unitType = unitType;
    }

    public Page check() {
        if (minPrice != null && maxPrice != null) {
            if (minPrice <= 0 || maxPrice >= Integer.MAX_VALUE || maxPrice < minPrice) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        } else if (minPrice != null) {
            if (minPrice <= 0 || minPrice >= Integer.MAX_VALUE) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        } else if (maxPrice != null) {
            if (maxPrice <= 0 || maxPrice >= Integer.MAX_VALUE) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
        if (status != null && status != 0 && status != 1 && status != 2) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        return this;
    }

    public static boolean checkAllStatus(Integer status) {
        if(status == null){
            return false;
        }
        if(status != Const.HOUSE_STATUS_ING && status != Const.HOUSE_STATUS_ON && status != Const.HOUSE_STATUS_OFF){
            return false;
        }
        return true;
    }

    public static boolean checkWebStatus(Integer status) {
        if(status == null){
            return false;
        }
        if(status != Const.HOUSE_STATUS_ON && status != Const.HOUSE_STATUS_OFF){
            return false;
        }
        return true;
    }

    public static boolean checkFace(Integer face) {
        if(face == null){
            return false;
        }
        if(face != Const.NORTH && face != Const.SOUTH && face != Const.EAST && face != Const.WEST){
            return false;
        }
        return true;
    }
}

